package com.desire.common;

/**
 * 为了避免出现代码冗余情况，应该增加工具类，封装请求失败和成功时候的方法，这里可使用静态方法
 */
public class ResultUtil {
    public static Result<Object> success(ResultEnum resultEnum, Object object) {
        Result<Object> result = new Result<>();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        result.setData(object);
        return result;
    }

    public static Result<Object> error(ResultEnum resultEnum) {
        Result<Object> result = new Result<>();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        return result;
    }
    public static Result<Object> error(String errMsg) {
        Result<Object> result = new Result<>();
        result.setCode(500);
        result.setMsg(errMsg);
        return result;
    }

}
